import Vue from 'vue'
import VueRouter from 'vue-router'
import uregister from '../views/register/uregister.vue'
import mregister from '../views/register/mregister.vue'
import ulogin from '../views/login/ulogin.vue'
import mlogin from '../views/login/mlogin.vue'
import slogin from '../views/login/slogin.vue'

Vue.use(VueRouter)

const routes = [
  // {
  //   path: '/topnav',
  //   name: 'topnav',
  //   component: () =>
  //     import('@/components/topnav.vue')
  // },
  {
    path: '/index',
    name: 'index',
    component: () =>
      import('@/views/index.vue'),
    children: [
      {
        path: '/bookall',
        name: 'bookall',
        component: () =>
          import('@/views/bookall.vue')
      }
    ]
  },
  {
    path: '/storeall',
    name: 'storeall',
    component: () =>
      import('@/views/storeall.vue')
  },
  {
    path: '/bookall',
    name: 'bookall',
    component: () =>
      import('@/views/bookall.vue')
  },
  {
    path: '/changepass',
    name: 'changepass',
    component: () =>
      import('@/views/dropdown/changepass.vue')
  },
  {
    path: '/address',
    name: 'address',
    component: () =>
      import('@/views/dropdown/address.vue')
  },
  {
    path: '/sindex',
    name: 'sindex',
    component: () =>
      import('@/views/sindex.vue')
  },
  {
    path: '/core',
    name: 'core',
    component: () =>
      import('@/views/core.vue')
  },
  {
    path: '/manage',
    name: 'manage',
    component: () =>
      import('@/views/manage.vue')
  },

  {
    path: '/login',
    component: () =>
      import('@/views/login.vue'),
    children: [{
      path: 'mlogin',
      name: 'mlogin',
      component: mlogin
    },
    {
      path: 'ulogin',
      name: 'ulogin',
      component: ulogin
    },
    {
      path: 'slogin',
      name: 'slogin',
      component: slogin
    },

    {
      path: '',
      redirect: '/login/ulogin'
    }
    ]
  },
  {
    path: '/register',
    component: () =>
      import('@/views/register.vue'),
    children: [{
      path: 'mregister',
      name: 'mregister',
      component: mregister
    },
    {
      path: 'uregister',
      name: 'uregister',
      component: uregister
    },
    {
      path: '',
      redirect: '/register/uregister'
    }]
  },
  {
    path: '',
    redirect: '/index'
  }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// 全局路由守卫
// router.beforeEach((to, from, next) => {
//   if (to.fullPath === '/navMenu') {
//     if (!localStorage.getItem('token')) {
//       next('/login/ulogin')
//     } else {
//       next()
//     }
//   } else {
//     next()
//   }
// })
// 路由前置守卫
// router.beforeEach((to, from, next) => {
//   // start progress bar

//   // 判断有无token
//   if (JSON.parse(localStorage.getItem('userToken'))) {
//     // 判断是否去登录页，如果是，直接跳转到主页；不是直接放行
//     if (to.path === '/login/ulogin') {
//       // 跳转到主页
//       next({ path: '/' })
//     }
//   }
// })

export default router
